<?php

class m120329_050139_add_table_comment extends CDbMigration
{
	public $table = 'comment';

	public function up()
	{
		$this->createTable(
			$this->table,
			array(
				'id'				=>'pk', //primary key
				'description'		=>'text',
				'user_id' 			=>'int unsigned not null',
				'prayer_id'			=>'int not null',
				'created_at'		=>'datetime',
				'updated_at'		=>'datetime'
			),
			'ENGINE=InnoDB CHARACTER SET utf8' // we need InnoDB for the indexes
			);
			
			$this->createIndex( 'fk_comment_user_id', $this->table, 'user_id' );
			$this->createIndex( 'fk_comment_prayer_id', $this->table, 'prayer_id' );
			
			$this->addForeignKey('fk_comment_user_id', $this->table,
			'user_id', 'user', 'id', 'NO ACTION', 'NO ACTION');
			
			$this->addForeignKey('fk_comment_prayer_id', $this->table,
			'prayer_id', 'prayer', 'id', 'NO ACTION', 'NO ACTION');
	}

	public function down()
	{
		$this->dropTable( $this->table );
	}

}